package it.rap.applications.movimenti.ricerche.widget;

import java.math.BigDecimal;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public class DataNavigator extends Composite {

	private static final long serialVersionUID = 7442471783246960803L;

	private Label navigatorLabel;
	private Composite contentComp;
	private BigDecimal currentDataOffset;
	private BigDecimal currentDataLimit;
	private BigDecimal totaleMovimenti;
	

	public DataNavigator(Composite parent,BigDecimal currentDataOffset, BigDecimal currentDataLimit, BigDecimal totaleMovimenti) {
		super(parent, SWT.NONE);
		RowLayout rl_compositeDataNavigator = new RowLayout(SWT.HORIZONTAL);
		rl_compositeDataNavigator.center = true;
		setLayout( rl_compositeDataNavigator);
		
		this.currentDataOffset = currentDataOffset;
		this.currentDataLimit = currentDataLimit;
		this.totaleMovimenti = totaleMovimenti;
		contentComp = createControl();
		refresh();
	}

	private Composite createControl(){			
		navigatorLabel = new Label( this, SWT.SHADOW_IN);		
		navigatorLabel.setText("dataNavigator");
		return this;		
	}
	
	public void refresh(){
		if( navigatorLabel != null ){
			try {
				navigatorLabel.setText( new StringBuffer("records: ").append( currentDataOffset ).append( " To " ).append( currentDataOffset.add( currentDataOffset.add( currentDataOffset.add( currentDataLimit )  ).compareTo( totaleMovimenti )<=0?currentDataLimit:totaleMovimenti.subtract( currentDataOffset  ) ) ).append(" of ").append( ""+totaleMovimenti ).toString() );
			} catch (Exception e ){
				
			}
			navigatorLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
		}
		getParent().redraw();
	}
	
	public void setVisible(boolean visible){
		navigatorLabel.setVisible(visible);
	}

	/**
	 * @return the navigatorLabel
	 */
	public Label getNavigatorLabel() {
		return navigatorLabel;
	}

	/**
	 * @param navigatorLabel the navigatorLabel to set
	 */
	public void setNavigatorLabel(Label navigatorLabel) {
		this.navigatorLabel = navigatorLabel;
	}

	/**
	 * @return the contentComp
	 */
	public Composite getContentComp() {
		return contentComp;
	}

	/**
	 * @param contentComp the contentComp to set
	 */
	public void setContentComp(Composite contentComp) {
		this.contentComp = contentComp;
	}

	/**
	 * @return the currentDataOffset
	 */
	public BigDecimal getCurrentDataOffset() {
		return currentDataOffset;
	}

	/**
	 * @param currentDataOffset the currentDataOffset to set
	 */
	public void setCurrentDataOffset(BigDecimal currentDataOffset) {
		this.currentDataOffset = currentDataOffset;
	}

	/**
	 * @return the currentDataLimit
	 */
	public BigDecimal getCurrentDataLimit() {
		return currentDataLimit;
	}

	/**
	 * @param currentDataLimit the currentDataLimit to set
	 */
	public void setCurrentDataLimit(BigDecimal currentDataLimit) {
		this.currentDataLimit = currentDataLimit;
	}

	/**
	 * @return the totaleMovimenti
	 */
	public BigDecimal getTotaleMovimenti() {
		return totaleMovimenti;
	}

	/**
	 * @param totaleMovimenti the totaleMovimenti to set
	 */
	public void setTotaleMovimenti(BigDecimal totaleMovimenti) {
		this.totaleMovimenti = totaleMovimenti;
	}

}